package cn.xopencode.recordservice.dal.mysql.mapper.roomin;

import cn.xopencode.common.framework.util.DateUtil;
import cn.xopencode.mybatis.core.query.QueryWrapperX;
import cn.xopencode.recordservice.dal.mysql.dataobject.roomin.RoomInRecordDO;
import cn.xopencode.recordservice.service.roomin.bo.AdminRoomInRecordBO;
import cn.xopencode.recordservice.service.roomin.bo.RoomInRecordPageBO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface RoomInRecordMapper extends BaseMapper<RoomInRecordDO> {

    default IPage<RoomInRecordDO> selectPage(RoomInRecordPageBO pageBO){
        if(pageBO.getInDatetime() != null){
            String inDateTime = DateUtil.format(pageBO.getInDatetime(), "yyyy-MM-dd");
            return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
                    new QueryWrapperX<RoomInRecordDO>()
                            .betweenIfPresent("in_datetime",inDateTime + " 00:00:00",inDateTime + " 23:59:59")
                            .orderByDesc("in_datetime"));
        }
        return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
                new QueryWrapperX<RoomInRecordDO>().orderByDesc("in_datetime"));
    }


    /**
     * 后台按条件分页查询列表数据
     * @param page
     * @param pageBO
     * @return
     */
    IPage<RoomInRecordDO> adminQuery(Page page, @Param("pageBO") AdminRoomInRecordBO pageBO);
}
